package MyGui;

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

import BackGround.*;
import Element.*;
import Element.Geom.*;
import DistSys.*;

public class StatusPanel extends JPanel {

  final int NUM_LABLES=10;
  final int X1Y1=0,X2Y2=1, ID=2, NAME=3,DESC=4,TYPE=5,ZONE=6,KVA=7,VD=8,AMP=9;

  MainFrame mainFrame;
  JLabel[] sbLabels;
  Font f;

  public StatusPanel() {
      f= new Font("Dialog", Font.PLAIN,9);

      this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT,1,1));

      sbLabels = new JLabel[NUM_LABLES];
      for(int i=0; i<NUM_LABLES; i++){
          sbLabels[i] = new JLabel();
      }
      try {
          for(int i=0; i<NUM_LABLES; i++){
              sbLabels[i].setBorder(new BevelBorder (BevelBorder.LOWERED));
              if( i==X1Y1 || i==X2Y2 ){
                  sbLabels[i].setMinimumSize(new Dimension(120, 20));
                  sbLabels[i].setPreferredSize(new Dimension(120, 20));
              }
              else if( i==NAME || i==DESC || i==TYPE){ // maybe a long string required
                  sbLabels[i].setMinimumSize(new Dimension(120, 20));
                  sbLabels[i].setPreferredSize(new Dimension(120, 20));
              }
              else{
                  sbLabels[i].setMinimumSize(new Dimension(80, 20));
                  sbLabels[i].setPreferredSize(new Dimension(80, 20));
              }
              if( i!=ID){ sbLabels[i].setFont( f ); }
              else { sbLabels[i].setFont( new Font("Dialog", Font.BOLD, 9)); }
              this.add(sbLabels[i]);
          }
      } catch(Exception e) {}
  }

  public void updateText(){
      if( Sys.focusElem == null ){
          clearText();
          return;
      }

      AbsElem elem = Sys.focusElem;
      AbsElemGeom g = elem.getElemGeomObj();
      sbLabels[X1Y1].setText("(x1,y1)=("+g.x1+","+g.y1+")");
      sbLabels[X2Y2].setText("(x2,y2)=("+g.x2+","+g.y2+")");
      sbLabels[X1Y1].setForeground(Color.blue);
      sbLabels[X2Y2].setForeground(Color.blue);

      if( elem instanceof BgLine || elem instanceof BgImage){
          for(int i=ID; i<=AMP; i++){
              if( i!= NAME ) { sbLabels[i].setText(" "); }
              else { sbLabels[i].setText( g.getName() ); }
          }
      } else {
          sbLabels[ID].setForeground(Color.red);
          sbLabels[ID].setText("Id="+(1+Sys.elemList.indexOf(elem)));
                                  //User's version= devloper's version +1
          sbLabels[NAME].setText (g.getName());
          sbLabels[DESC].setText( "DESC: " + g.getDesc());
          sbLabels[TYPE].setText( elem.getStringForType());
          sbLabels[ZONE].setText( Zone.getZoneString(elem.getData(AbsElem.DATA_ZONE)));
          sbLabels[KVA].setText ( "kVA: "+ elem.getData(AbsElem.RES_KVA_FLOW));
          sbLabels[VD].setText( "%VD: "+ elem.getData(AbsElem.RES_VOLT_DROP));
          sbLabels[AMP].setText( "Amps: "+ elem.getData(AbsElem.RES_CURR_MAG));
      }
  }

  public void clearText(){
      for(int i=0;i<NUM_LABLES;i++){
          sbLabels[i].setText("");
      }
  }
}